<?php
/**
 * 项目：红河移动电路资源管理信息系统
 *
 * 公司：红河移动分公司
 *
 * @author 李朝应
 *
 * E-mail:lichaoying.hh@163.com
 *
 */
class Req_model extends CI_Model {
   function __construct()
    {
        parent::__construct();
    }
  function setReq($data){
    $this->db->insert('req', $data);
    $this->db->select_max('id');
    $query = $this->db->get('req');
    foreach ($query->result_array() as $row)
  {
    $id=$row['id'];
   }
   return $id;//返回最后影响的ID
  }
  function updateReq($id,$data){
    $this->db->where('id',$id);
    $this->db->update('req', $data);
    return $this->db->affected_rows() ;
  }
 function getReqID($begin_string,$id){
  $sql="SELECT count(*)+1 as id from crms_req where Requisition_ID
like '$begin_string%' AND id != '$id'";
  $query = $this->db->query($sql);
 foreach ($query->result_array() as $row)
  {
    $id=$row['id'];
   }
   return $id;
 }
 function getReqByID($req_id){
   $this->db->where("Requisition_ID",$req_id);
   $query = $this->db->get('req');
   if ($query->num_rows() > 0)
		{
		  return $query->row_array(); //返回查询结果
        }
 }
  function getReqByOrderID($id){
   $this->db->where("id",$id);
   $this->db->where("state","1");
   $query = $this->db->get('req');
   if ($query->num_rows() > 0)
		{
		  return $query->row_array(); //返回查询结果
        }
 }
 function getReqByOrderID2($id){
   $this->db->where("id",$id);
   $this->db->where("state !=","1");
   $query = $this->db->get('req');
   if ($query->num_rows() > 0)
		{
		  return $query->row_array(); //返回查询结果
        }
 }
 function getReqByOrderID3($id){
   $this->db->where("id",$id);
   $this->db->where("state =","2");
   $query = $this->db->get('req');
   if ($query->num_rows() > 0)
		{
		  return $query->row_array(); //返回查询结果
        }
 }
 function getPath($id){
   $this->db->select("File_Path as path");
   $this->db->where("id",$id);
   $query = $this->db->get('req');
    foreach ($query->result_array() as $row)
  {
    $path=$row['path'];
   }
   return $path;
 }
  function getReqId2($id){
   $this->db->select("Requisition_ID as id");
   $this->db->where("id",$id);
   $query = $this->db->get('req');
    foreach ($query->result_array() as $row)
  {
    $id_=$row['id'];
   }
   return $id_;
 }
   function getReqLoginByID($id){
   $this->db->select("us_login as login");
   $this->db->where("id",$id);
   $query = $this->db->get('req');
    foreach ($query->result_array() as $row)
  {
    $login=$row['login'];
   }
   return $login;
 }
 function getTotalCg($org1_id,$login){
    $fld="crms_type.type as type,crms_req.id as id,crms_req.org1_id as org1_id,
      crms_req.Draft as Draft,crms_req.update_time as update_time,crms_type.id as type_id,
      crms_req.Requisition_ID as Requisition_ID,crms_req.state as state";
   $sql="select ". $fld." from crms_req,crms_type where crms_req.type=crms_type.type_id
   AND crms_req.org1_id='$org1_id'
   AND crms_req.us_login='$login'
   AND crms_req.state='1' order by crms_req.update_time desc";
   $query = $this->db->query($sql);
    return $query->num_rows();
 }
 function getRegCg($org1_id,$login){
   $fld="crms_type.type as type,crms_req.id as id,crms_req.org1_id as org1_id,
      crms_req.Draft as Draft,crms_req.update_time as update_time,crms_type.id as type_id,
      crms_req.Requisition_ID as Requisition_ID,crms_req.state as state";
   $sql="select ". $fld." from crms_req,crms_type where crms_req.type=crms_type.type_id
   AND crms_req.org1_id='$org1_id'
   AND crms_req.us_login='$login'
   AND crms_req.state='1' order by crms_req.update_time desc";
   $query = $this->db->query($sql);
   if ($query->num_rows() > 0)
		{
		  return $query; //返回查询结果
        }
 }
 function getTotalDo($org1_id,$login){
   $fld="crms_type.type as type,crms_req.id as id,crms_req.org1_id as org1_id,
      crms_req.Draft as Draft,crms_req.update_time as update_time,crms_type.id as type_id,
      crms_req.Requisition_ID as Requisition_ID,crms_req.state as state";
   $sql="select ". $fld." from crms_req,crms_type where crms_req.type=crms_type.type_id
   AND crms_req.org1_id='$org1_id'
   AND crms_req.us_login='$login'
   AND crms_req.state='2' order by crms_req.update_time desc";
   $query = $this->db->query($sql);
   return $query->num_rows();
 }
 function getRegDo($org1_id,$login,$a,$b){
  $fld="crms_type.type as type,crms_req.id as id,crms_req.org1_id as org1_id,
      crms_req.Draft as Draft,crms_req.update_time as update_time,crms_type.id as type_id,
      crms_req.Requisition_ID as Requisition_ID,crms_req.state as state";
   $sql="select ". $fld." from crms_req,crms_type where crms_req.type=crms_type.type_id
   AND crms_req.org1_id='$org1_id'
   AND crms_req.us_login='$login'
   AND crms_req.state='2' order by crms_req.update_time desc LIMIT $a,$b";
   $query = $this->db->query($sql);
   if ($query->num_rows() > 0)
		{
		  return $query; //返回查询结果
        }
 }
 function getTotalYgd($org1_id){
   $fld="crms_type.type as type,crms_req.id as id,crms_req.org1_id as org1_id,
      crms_req.Draft as Draft,crms_req.update_time as update_time,crms_type.id as type_id,
      crms_req.Requisition_ID as Requisition_ID,crms_req.state as state";
   $sql="select ". $fld." from crms_req,crms_type where crms_req.type=crms_type.type_id
   AND crms_req.org1_id='$org1_id'
   AND crms_req.state='3'order by crms_req.update_time desc ";
   $query = $this->db->query($sql);   
    return $query->num_rows();
 }
  function getRegYgd($org1_id,$a,$b){
  $fld="crms_type.type as type,crms_req.id as id,crms_req.org1_id as org1_id,
      crms_req.Draft as Draft,crms_req.update_time as update_time,crms_type.id as type_id,
      crms_req.Requisition_ID as Requisition_ID,crms_req.state as state";
   $sql="select ". $fld." from crms_req,crms_type where crms_req.type=crms_type.type_id
   AND crms_req.org1_id='$org1_id'
   AND crms_req.state='3'order by crms_req.update_time desc LIMIT $a,$b";
   $query = $this->db->query($sql);
   if ($query->num_rows() > 0)
		{
		  return $query; //返回查询结果
        }
 }
  function getTotalAll($org1_id){
   $fld="crms_type.type as type,crms_req.id as id,crms_req.org1_id as org1_id,crms_req.state as state,
      crms_req.Draft as Draft,crms_req.update_time as update_time,crms_type.id as type_id,
      crms_req.Requisition_ID as Requisition_ID,crms_req.state as state";
   $sql="select ". $fld." from crms_req,crms_type where crms_req.type=crms_type.type_id
   AND crms_req.org1_id='$org1_id'
   AND crms_req.state!='1'order by crms_req.update_time desc";
   $query = $this->db->query($sql);  
     return $query->num_rows();
  }
 function getRegAll($org1_id,$a,$b){
  $fld="crms_type.type as type,crms_req.id as id,crms_req.org1_id as org1_id,crms_req.state as state,
      crms_req.Draft as Draft,crms_req.update_time as update_time,crms_type.id as type_id,
      crms_req.Requisition_ID as Requisition_ID,crms_req.state as state";
   $sql="select ". $fld." from crms_req,crms_type where crms_req.type=crms_type.type_id
   AND crms_req.org1_id='$org1_id'
   AND crms_req.state!='1'order by crms_req.update_time desc LIMIT $a,$b";
   $query = $this->db->query($sql);
   if ($query->num_rows() > 0)
		{
		  return $query; //返回查询结果
        }
 }
  function getRegAllbyBrowser($org1_id){
   $fld="crms_req.Requisition_ID";
   $sql="select ". $fld." from crms_req,crms_type where crms_req.type=crms_type.type_id
   AND crms_req.org1_id='$org1_id'
   AND crms_req.state!='1'order by crms_req.update_time desc";
   $query = $this->db->query($sql);
   if ($query->num_rows() > 0)
		{
		  return $query; //返回查询结果
        }
 }
 function getTotalFind($org1_id,$req_id,$draft,$router,$send,$notify,$mon,$type){
   $fld="crms_type.type as type,crms_req.id as id,crms_req.org1_id as org1_id,crms_req.state as state,
      crms_req.Draft as Draft,crms_req.update_time as update_time,crms_type.id as type_id,
      crms_req.Requisition_ID as Requisition_ID,crms_req.state as state";
   $sql="select ". $fld." from crms_req,crms_type where crms_req.type=crms_type.type_id
   AND crms_req.org1_id='$org1_id'
   AND crms_req.state!='1'";
   if($req_id<>""){$sql.=" AND crms_req.Requisition_ID like'%$req_id%' ";}
   if($draft<>""){$sql.=" AND crms_req.Draft like'%$draft%' ";}
   if($router<>""){$sql.=" AND crms_req.Router like'%$router%' ";}
   if($send<>""){$sql.=" AND crms_req.Main_Send like'%$send%' ";}
   if($notify<>""){$sql.=" AND crms_req.Notify_Time='$notify' ";}
   if($mon<>""){$sql.=" AND crms_req.Req_Mon ='$mon' ";}
   if($type<>""){$sql.=" AND crms_req.type ='$type' ";}
   $sql.="order by crms_req.update_time desc";
   $query = $this->db->query($sql);
   return $query->num_rows();
 }
 function getFind($org1_id,$req_id,$draft,$router,$send,$notify,$mon,$type){
   $fld="crms_type.type as type,crms_req.id as id,crms_req.org1_id as org1_id,crms_req.state as state,
      crms_req.Draft as Draft,crms_req.update_time as update_time,crms_type.id as type_id,
      crms_req.Requisition_ID as Requisition_ID,crms_req.state as state";
   $sql="select ". $fld." from crms_req,crms_type where crms_req.type=crms_type.type_id
   AND crms_req.org1_id='$org1_id'
   AND crms_req.state!='1'";
   if($req_id<>""){$sql.=" AND crms_req.Requisition_ID like'%$req_id%' ";}
   if($draft<>""){$sql.=" AND crms_req.Draft like'%$draft%' ";}
   if($router<>""){$sql.=" AND crms_req.Router like'%$router%' ";}
   if($send<>""){$sql.=" AND crms_req.Main_Send like'%$send%' ";}
   if($notify<>""){$sql.=" AND crms_req.Notify_Time='$notify' ";}
   if($mon<>""){$sql.=" AND crms_req.Req_Mon ='$mon' ";}
   if($type<>""){$sql.=" AND crms_req.type ='$type' ";}
   $sql.="order by crms_req.update_time desc";
   $query = $this->db->query($sql);
     if ($query->num_rows() > 0)
		{
		  return $query; //返回查询结果
        }
 }
 function delReqbyID($id){
   $this->db->where("id",$id);
   $this->db->delete('req');
   return true;

 }
 function savereq_gd($text,$id){
    $data = array(
               'say_req' => $text,
               'state' => "3",
            );
    $this->db->where('id',$id);
    $this->db->where('state',"2");
    $this->db->update('req', $data);
    return $this->db->affected_rows() ;
 }
}//end class

?>
